function [answer i]=powermethod(SinvM)

% check inputs
if (sum(sum(isnan (SinvM)))>0  )
    error ('SinvM must be numbers') ;
end

	% now do power method

	
	n=length(SinvM);
	
	guess=normrnd(0,1,n,1);
	guess=guess./sum(abs(guess));  % normalize to sum to one 
	guess=abs(guess);
	gap=sum(abs(guess));
	tol=0.00000001;
	i=0;
	
	
	
	while gap>tol  && i<500
		i=i+1;
		guessnew=SinvM*guess;
		guessnew=guessnew./sum(abs(guessnew));
		gap=sum(abs(guess-guessnew));
		guess=guessnew;
	end;

	answer=guess;

end